<template>
    <h1>这是投资信息修改页面</h1>

    <table>
        <tr>
            <td>投资项目名称</td>
            <td>
                <input type="text" v-model="Info.I_Name" />
            </td> 
        </tr>

        <tr>
            <td>投资总额度</td>
            <td>
                <input type="text" v-model="Info.I_Budget" />
            </td>
        </tr>

        <tr>
            <td colspan="2">
                <input type="button" value="修改" @click="Edit" /> 
            </td>
        </tr>
    </table>

</template>

<script setup lang="ts">
import { useRoute  } from 'vue-router';
import { ref,onMounted } from 'vue';
import axios from 'axios';  
import { useRouter } from 'vue-router';

const router = useRouter();

const route = useRoute();
const Id=route.params.Iid;

onMounted(()=>{
    ServerInfo();
})

const Info = ref({
    I_Name:'',
    I_Budget:'',
})  

//反填
const ServerInfo = () => {
    axios({
        url:'http://localhost:53279/api/Invest/ServerInfo',
        method:'get',
        params:{
            Iid:Id
        }
    })
    .then(function(res){
        Info.value.I_Name = res.data.I_Name;
        Info.value.I_Budget = res.data.I_Budget;
    })
    .catch(function(err){
        console.log(err);
    })
}


//修改
const Edit = () => {
    axios({
        url:'http://localhost:53279/api/Invest/Update',
        method:'post',
        data:{
            I_Id:Id,
            I_Name:Info.value.I_Name,
            I_Budget:Info.value.I_Budget
        }
    })
    .then(function(res){
        if(res.data==1){
            alert('修改成功');
            router.push('/StaffInversShow');
        }
        else{
            alert('修改失败');
            return;
        }
    })
}
</script>